package Annotations;

import bean.Kunde;
import java.math.BigInteger;
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;


public class MaxKreditValidator implements ConstraintValidator<MaxKredit, Kunde>
{

    @Override
    public void initialize(MaxKredit a) {
        
    }

    @Override
    public boolean isValid(Kunde t, ConstraintValidatorContext cvc) {
        BigInteger summeKredite = new BigInteger("0");
        for(int i=0; i<t.numKreditgeber(); i++){
            summeKredite = summeKredite.add( t.getKredit(i).getSumme() );
        }
        if( summeKredite.compareTo(t.getMaxKredit()) >0){
            return false;
        }
        return true;
    }


    
}